package cookie

import (
	"net/http"
	"time"
	"encoding/base64"
)

func NewCookie(name, value string, age int64) *http.Cookie {
	var utctime time.Time
	if age == 0 {
		// 2^31 - 1 seconds (roughly 2038)
		utctime = time.Unix(2147483647, 0)
	} else {
		utctime = time.Unix(time.Now().Unix() + age, 0)
	}
	value = base64.StdEncoding.EncodeToString([]byte(value))
	return &http.Cookie{Name: name, Value: value, Expires: utctime}
}
